fix(agent): reject unsafe mandate numeric fields - #284
Conversation
|
@emrekayat Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
There was a problem hiding this comment.
Pull request overview
This PR implements stricter numeric validation for session mandate payloads at both creation and verification boundaries, aiming to reject unsafe numeric inputs (NaN/Infinity/fractional/unsafe-integer) with stable MandateError messages, and adds regression tests for malformed values.
Changes:
- Added centralized numeric field validation (
validateMandateNumbers) to enforce safe integers for timestamps/prices and integer-only strings for round IDs and stroop fields. - Applied the new validation in both
createSessionMandateandverifySessionMandatefor consistent, stable error behavior. - Added tests covering unsafe/malformed mandate fields and signature-preserving malformed payload scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| services/agent/src/mandate.ts | Introduces numeric validation helpers and enforces them during mandate creation and verification. |
| services/agent/src/mandate.test.ts | Adds tests to ensure unsafe/malformed mandate fields are rejected with stable MandateError messages. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| issuedAt: now, | ||
| expiresAt: now + (params.ttlSeconds ?? 3600), | ||
| }; | ||
| validateMandateNumbers(payload); |
| assert.throws( | ||
| () => createSessionMandate({ ...p, roundId: 1.5 }), | ||
| (error: unknown) => error instanceof MandateError && error.message === "invalid mandate roundId", | ||
| ); | ||
| }); |
Fixes #273.
Validates mandate timestamps, prices, round IDs, and stroop strings at creation and verification boundaries with stable MandateError messages. Adds boundary and malformed-value tests.